package com.gd.iot.energy.controller.superadmin;

import com.gd.iot.energy.annotation.SystemLogRecordMonitor;
import com.gd.iot.energy.entity.ResponseEntity;
import com.gd.iot.energy.pojo.superadmin.dto.AdminDTO;
import com.gd.iot.energy.pojo.superadmin.dto.AdminSaveDTO;
import com.gd.iot.energy.pojo.superadmin.vo.AdminPageVO;
import com.gd.iot.energy.pojo.common.vo.PageVO;
import com.gd.iot.energy.pojo.superadmin.vo.AdminVO;
import com.gd.iot.energy.service.superadmin.AdminService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 超级管理-用户管理-用户管理
 *
 * @author kris
 * @date Created at 2020/8/3 10:50
 */
@Api(value = "超级管理-用户管理-用户管理",tags = "超级管理-用户管理-用户管理")
@RestController
@RequestMapping("/admin/admin")
public class AdminController {

    @Autowired
    private AdminService adminService;

    @ApiOperation("后台管理员分页列表")
    @SystemLogRecordMonitor("后台管理员分页列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "username", value = "用户名", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "name", value = "姓名", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "email", value = "邮箱", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "pageNum", value = "页码", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "orderColumn", value = "排序字段", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "orderType", value = "排序类型(asc,desc)", dataType = "string", paramType = "query", example = "", required = false),
    })
    @PostMapping("/getPageList")
    public ResponseEntity<PageVO<AdminPageVO>> getPageList(
            @RequestParam(value = "username",required = false)String username,
            @RequestParam(value = "name",required = false)String name,
            @RequestParam(value = "email",required = false)String email,
            @RequestParam(value = "pageSize",required = false,defaultValue = "10")Integer pageSize,
            @RequestParam(value = "pageNum",required = false,defaultValue = "1")Integer pageNum,
            @RequestParam(value = "orderColumn",required = false,defaultValue = "id") String orderColumn,
            @RequestParam(value = "orderType",required = false,defaultValue = "asc") String orderType
    ) {

        PageVO<AdminPageVO> pageVO = adminService.getPageAdminVOs(username,name,email,pageSize,pageNum,orderColumn,orderType);
        return new ResponseEntity<>(pageVO);
    }

    @ApiOperation("获取所有管理员列表")
    @SystemLogRecordMonitor("获取所有管理员列表")
    @PostMapping("/getAllAdmin")
    public ResponseEntity<List<AdminVO>> getAllAdmin(){
        List<AdminVO> adminVOS = adminService.getAllAdmin();
        return new ResponseEntity<>(adminVOS);
    }

    @ApiOperation("通过id获取管理员")
    @SystemLogRecordMonitor("通过id获取管理员")
    @PostMapping("/get")
    public ResponseEntity<AdminSaveDTO> get(Integer id){
        AdminSaveDTO roleVO = adminService.getAdmin(id);
        return new ResponseEntity<>(roleVO);
    }

    @ApiOperation("新增管理员")
    @SystemLogRecordMonitor("新增管理员")
    @PostMapping("/add")
    public ResponseEntity<Long> add(@RequestBody AdminSaveDTO adminSaveDTO){
        Long id = adminService.add(adminSaveDTO);
        return new ResponseEntity<>(id);
    }

    @ApiOperation("更新管理员")
    @SystemLogRecordMonitor("更新管理员")
    @PostMapping("/update")
    public ResponseEntity<Boolean> update(@RequestBody AdminSaveDTO adminSaveDTO){
        boolean res = adminService.updateAdmin(adminSaveDTO);
        return new ResponseEntity<>(res);
    }

    @ApiOperation("删除管理员")
    @SystemLogRecordMonitor("删除管理员")
    @PostMapping("/delete")
    public ResponseEntity<Boolean> delete(@RequestBody List<Integer> ids){
        boolean res = adminService.delete(ids);
        return new ResponseEntity<>(res);
    }

}
